<template>
<div>
  <div>
    <Button type="info" @click="add">增加图书</Button>
  </div>
  <Table border :columns="columns12" :data="data">
    <template slot-scope="{ row }" slot="name">
      <strong>{{ row.name }}</strong>
    </template>
    <template slot-scope="{ row, index }" slot="action">
      <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">编辑</Button>
      <Button type="error" size="small" @click="remove(row)">删除</Button>
    </template>
  </Table>
  <el-dialog :visible.sync="addBook" v-if="addBook" :close-on-click-modal="false">
    <addBook @after="getInformation" @hideDialog="heidden" ></addBook>
  </el-dialog>
  <el-dialog :visible.sync="UpdateBook" v-if="UpdateBook" :close-on-click-modal="false">
    <UpdateBook @after="getInformation" :data="formData" @hideDialog="heidden"></UpdateBook>
  </el-dialog>
</div>
</template>

<script>
import addBook from '_c/Book/addBook'
import UpdateBook from "_c/Book/UpdateBook";
export default {
  name: "Book",
  components: {addBook,UpdateBook},
  data () {
    return {
      addBook:false,
      UpdateBook:false,
      columns12: [
        {
          title: '书名称',
          slot: 'name'
        },
        {
          title: '书名称',
          key: 'author'
        },
        {
          title: '出版社',
          key: 'publish'
        },
        {
          title: '标准书号',
          key: 'isbn'
        },
        {
          title: '书介绍',
          key: 'introduction'
        },
        {
          title: '语言',
          key: 'language'
        },
        {
          title: '价格信息',
          key: 'price'
        },
        {
          title: '出版时间',
          key: 'pub_date'
        },
        {
          title: '图书类型',
          key: 'type_id'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      data: []
    }
  },
  methods: {
    show (row) {
      this.UpdateBook=true;
      this.formData=row
    },
    remove (row) {
      this.$confirm('确定删除吗','提示').then(()=>{
        this.http.post("deleteInformation",row).then(res=>{
          if (res.data){
            this.$Message.success('删除成功')
            this.getInformation();
          }else {
            this.$Message.error('删除失败')
          }
        })
      })
    },
    getInformation(){
      this.http.post("get").then(res=>{
        if (res.data){
          this.data=res.data
        }
      })
    },
    add(){
      this.addBook=true
    },
    heidden(){
      this.addBook=false
      this.UpdateBook=false
    }
  },
  created() {
    this.getInformation();
  }
}
</script>

<style scoped>

</style>
